Find the number of ways to make a target sum using coins with infinite supply
Determine the number of ways to make a target sum using an infinite supply of given coin denominations with dynamic programming.
Coins:
Output: 3
Coins:
Output: 4
| Sum | 0 | 1 | 2 | 3 |
|---|---|---|---|---|
| After coin 1 | 1 | 1 | 1 | 1 |
| After coin 2 | 1 | 1 | 2 | 2 |
Output: 2 (ways: [1,1,1], [1,2])
Iterate over n coins and s sums
For the DP array
Example 1: n=3, coins=[1,2,3], s=3 → 3
Example 2: n=3, coins=[1,2,3], s=4 → 4
Iterate over n coins and s sums
For the DP array